package com.ruoyi.dynamic.controller.app;


import com.ruoyi.common.core.constant.constant.PathConstant;
import com.ruoyi.common.core.context.SecurityContextHolder;
import com.ruoyi.common.core.pojo.vo.SingleVO;
import com.ruoyi.common.core.result.Result;
import com.ruoyi.dynamic.model.pojo.entity.Room;
import com.ruoyi.dynamic.model.pojo.request.app.AppRoomSetGiftRequest;
import com.ruoyi.dynamic.model.pojo.request.app.AppRoomSetUpdateRequest;
import com.ruoyi.dynamic.model.pojo.result.app.AppRoomSetResult;
import com.ruoyi.dynamic.service.IRoomService;
import com.ruoyi.dynamic.service.IRoomSetService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Tag(name = "App-房间设置", description = "App-房间设置")
@RestController
@RequestMapping(PathConstant.APP_PATH + "room-set")
public class AppRoomSetController {

    private final IRoomSetService iRoomSetService;
    private final IRoomService iRoomService;

    public AppRoomSetController(IRoomSetService iRoomSetService, IRoomService iRoomService) {
        this.iRoomSetService = iRoomSetService;
        this.iRoomService = iRoomService;
    }

    @Operation(summary = "获取房间设置", description = "获取房间设置")
    @GetMapping
    public SingleVO<AppRoomSetResult> getUserRoomSet(@Parameter(description = "房间id") Long roomId) {
        Long userId = null;
        if (roomId == null) {
            userId = SecurityContextHolder.getUserId();
        } else {
            Room verify = iRoomService.verify(roomId);
            userId = verify.getUserId();
        }
        return Result.single(iRoomSetService.getUserRoomSet(userId));
    }

    @Operation(summary = "更新房间设置", description = "更新房间设置")
    @PostMapping("updateRoomSet")
    public SingleVO<AppRoomSetResult> updateRoomSet(@RequestBody @Validated AppRoomSetUpdateRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        AppRoomSetResult one = iRoomSetService.updateRoomSet(userId, request);
        return Result.single(one);
    }

    @Operation(summary = "房间设置提问礼物", description = "更新房间设置")
    @PostMapping("setGift")
    public SingleVO<AppRoomSetResult> setGift(@RequestBody @Valid AppRoomSetGiftRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        AppRoomSetResult one = iRoomSetService.setGift(userId, request.getGiftId());
        return Result.single(one);
    }

}

